var request = require('request');
var log=require("../paca/plog");


//==============================================================================
// PacaMsg 消息体
var PMSG = function (){
	this.cmd="";
	this.subcmd="";
	this.err=0;
	this.errmsg="";
	this.passwd="";
	this.ck="";
	this.val=null
}
module.exports = PMSG; 

//==============================================================================
// 发送消息， 并且获得消息返回 
module.exports.Send = function(serveradd, msg, cb)
{
	//log.out("send a msg");
	var str = JSON.stringify(msg);
	request.post(
		{
			url:serveradd, 
			form:{
				input:str
			},
			encoding:'utf8'
		},
		function(error, response, body)
		{
			if (!error && response.statusCode == 200) {
				//log.out(" json is " + body);
                                //console.log("ddddddddddddddd"+body);
				var obj = JSON.parse(body);
				if(cb!= null)
					cb(obj, body);
			} else {
				log.out("err http request");
			}
		}
	);
}
/*
request.post(
	{
		url:"http://www.baidu.com",
		form:{
		},
		encoding:'utf8'
	},
	function(error, response, body)
	{
		console.log(body);
	}
);

request('http://www.baidu.com', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // Print the google web page.
  }
})*/
/*
var pmsg = require("./pmsg");

var x = new pmsg();
x.cmd = "xxx";
x.subcmd = "xxx";
pmsg.Send(x, 
	function(m)
	{
		console.log(m.cmd);
	}
)
*/
